﻿using MCommons.MImage;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using WpfApp1.Dto;

namespace WpfApp1.Models
{
    public class UploadViewModel : INotifyPropertyChanged
    {
        public UploadViewModel(UploadFamilyInfo dto)
        {
            this.IsSelectProperty = dto.IsSelect;
            this.Name = dto.Name;
            this.Pic = ImageUtils.ConvertBitmap(ImageUtils.CreateImage(dto.PicUrl, 80, 100));
            this.Type = "选择类型";
            Visibility = Visibility.Visible;
        }

        public UploadViewModel()
        {
            IsSelect = false;
            Name = "";
            Pic = null;
            Type = "";
            Visibility = Visibility.Hidden;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        /// <summary>
        /// 属性刷新
        /// </summary>
        /// <param name="name">发生改变的属性名称</param>
        public virtual void RefrshProperty([CallerMemberName] string name = "")
        {
            if (this.PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        /// <summary>
        /// 是否上传
        /// </summary>
        private bool IsSelect { get;set; }
        
        public bool IsSelectProperty
        {
            get { return IsSelect; }

            set
            {
                this.IsSelect = value;
                this.RefrshProperty();
            }
        }

        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }

        private BitmapImage Pic { get; set; }

        /// <summary>
        /// 图片
        /// </summary>
        public BitmapImage PicProperty
        {
            get { return Pic; }

            set
            {
                this.Pic = value;
                this.RefrshProperty();
            }
        }

        /// <summary>
        /// 类型
        /// </summary>
        private string type;
        public string Type
        {
            get { return type; }

            set
            {
                this.type = value;
                this.RefrshProperty();
            }
        }

        /// <summary>
        /// 操作按钮是否显示
        /// </summary>
        public Visibility Visibility { get; set; }
    }
}
